<?php
/**
 * Interface zum Db_Connector
 *
 * @author		Joachim Ruf
 * @copyright	Copyright (c) 2003-2010 Loresoft Software (http://www.loresoft.de)
 * @license		http://yapary.loresoft.de/lizenzbedingungen     New BSD License
 *
 * */


class Yapary_Db_Sql_TableColInfo Implements Yapary_Db_ITableColInfo
{
    private $tableName    = NULL;
    private $colName      = NULL;
    private $connection   = NULL;


    function __construct ($_connection, $_tableName, $_colName) {
        $this->connection = $_connection;
        $this->tableName  = $_tableName;
        $this->colName    = $_colName;
    }


    /**
     * Prueft, ob die angegebene Spalete existiert
     * @return bool
     * */
    public function exists () {
		$resId = @mysql_query('SHOW COLUMNS FROM '.$this->tableName .' WHERE FIELD="'.$this->colName.'"', $this->connection);
		if (gettype($resId) !== 'resource') {
		    return false;
		    //trigger_error('FATAL ERROR in <b>'.__METHOD__.'</b> TMP data does not exist', E_USER_ERROR);
		}

        if (count(@mysql_fetch_array($resId)) == 1) {
            return true;
        }

		return false;
    }


    /**
     * Liefert den SQL-Datentyp
     * @return string|NULL
     * */
    public function getType () {
		$resId = @mysql_query('SHOW FULL COLUMNS FROM '.$this->tableName .' WHERE FIELD="'.$this->colName.'"', $this->connection);
		if (gettype($resId) !== 'resource') {
		    return NULL;
		}

	    $result = @mysql_fetch_array($resId);
        return $result['Type'];
    }


    /**
     * Liefert den SQL-Collation
     * @return string|NULL
     * */
    public function getCollation () {
		$resId = @mysql_query('SHOW FULL COLUMNS FROM '.$this->tableName .' WHERE FIELD="'.$this->colName.'"', $this->connection);
		if (gettype($resId) !== 'resource') {
		    return NULL;
		}

	    $result = @mysql_fetch_array($resId);
        return $result['Collation'];
    }


    /**
     * Liefert den SQL-Kommentar
     * @return string|NULL
     * */
    public function getComment () {
		$resId = @mysql_query('SHOW FULL COLUMNS FROM '.$this->tableName .' WHERE FIELD="'.$this->colName.'"', $this->connection);
		if (gettype($resId) !== 'resource') {
		    return NULL;
		}

	    $result = @mysql_fetch_array($resId);
        return $result['Comment'];
    }


}


?>